#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <pthread.h>

#include "idc_ubus.h"
#include "idc_ubus_bridge.h"
#include "bridge_service.h"

static const struct ubus_method idc_bridge_methods[] = {
        UBUS_METHOD("get_bridge_info", ubus_get_bridge_info, get_bridge_info_policy),
};
 
static struct ubus_object_type idc_bridge_object_type =  UBUS_OBJECT_TYPE("sihan.bridge", idc_bridge_methods);
 
 
static struct ubus_object idc_bridge_object = {
        .name = "sihan.bridge",
        .type = &idc_bridge_object_type,
        .methods = idc_bridge_methods,
        .n_methods = ARRAY_SIZE(idc_bridge_methods)
};
 
int ubus_doing()
{
        int ret;
 
        ctx = ubus_connect(NULL);
        if (!ctx) {
                fprintf(stderr, "Failed to connect to ubus\n");
                return -1;
        }
        ubus_add_uloop(ctx);
 
        ret = ubus_add_object(ctx, &idc_bridge_object);
        if (ret)
                fprintf(stderr, "Failed to add object: %s\n", ubus_strerror(ret));
        #if 0
        ret = ubus_register_subscriber(ctx, &test_event);
	if (ret)
		fprintf(stderr, "Failed to add watch handler: %s\n", ubus_strerror(ret));
        #endif
}
void *ubus_worker(void *arg)
{
     //   int res = read_tmp("/bin/bridge_tmp");
        //if(res == 0) {
                uloop_init();
                ubus_doing();
                uloop_run();
                ubus_free(ctx);
                uloop_done();
        //}
}
